package sword;

/**
 * @Author: 海琳琦
 * @Date: 2022/5/26 17:14
 * https://leetcode.cn/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/
 */
public class Title22 {

    class ListNode{
        int val;

        ListNode next;

        public ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public ListNode getKthFromEnd(ListNode head, int k) {
        int size = 0;
        ListNode cur = head;
        while (cur != null) {
            size++;
            cur = cur.next;
        }
        for (int i = 0; i < size - k; i++) {
            head = head.next;
        }
        return head;
    }

    public static void main(String[] args) {

    }
}
